package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.domain.AdvOrders;
import com.ruoyi.mapper.AdvOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.AdvOrdersdetailMapper;
import com.ruoyi.domain.AdvOrdersdetail;
import com.ruoyi.service.IAdvOrdersdetailService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-13
 */
@Service
public class AdvOrdersdetailServiceImpl implements IAdvOrdersdetailService
{
    @Autowired
    @Resource
    private AdvOrdersdetailMapper advOrdersdetailMapper;

    @Autowired
    @Resource
    private AdvOrdersMapper advOrdersMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param advOrdersdetailId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public AdvOrdersdetail selectAdvOrdersdetailByAdvOrdersdetailId(Long advOrdersdetailId)
    {
        return advOrdersdetailMapper.selectAdvOrdersdetailByAdvOrdersdetailId(advOrdersdetailId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param advOrdersdetail 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<AdvOrdersdetail> selectAdvOrdersdetailList(AdvOrdersdetail advOrdersdetail)
    {
        if (advOrdersdetail.getProductType().equals("1")){
            advOrdersdetail.setDnoOrdersno("DNO");
        }else if (advOrdersdetail.getProductType().equals("2")){
            advOrdersdetail.setDnoOrdersno("CNO");
            advOrdersdetail.setDnoOrdersnoTwo("SNO");
        }
        return advOrdersdetailMapper.selectAdvOrdersdetailList(advOrdersdetail);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param advOrdersdetail 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertAdvOrdersdetail(AdvOrdersdetail advOrdersdetail)
    {
        return advOrdersdetailMapper.insertAdvOrdersdetail(advOrdersdetail);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param advOrdersdetail 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateAdvOrdersdetail(AdvOrdersdetail advOrdersdetail)
    {
        return advOrdersdetailMapper.updateAdvOrdersdetail(advOrdersdetail);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param advOrdersdetailIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAdvOrdersdetailByAdvOrdersdetailIds(Long[] advOrdersdetailIds)
    {
        return advOrdersdetailMapper.deleteAdvOrdersdetailByAdvOrdersdetailIds(advOrdersdetailIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param advOrdersdetailId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAdvOrdersdetailByAdvOrdersdetailId(Long advOrdersdetailId)
    {
        return advOrdersdetailMapper.deleteAdvOrdersdetailByAdvOrdersdetailId(advOrdersdetailId);
    }
    /**
     * 硬件订单明细
     * @param advOrdersId
     * @return
     */
    @Override
    public List<AdvOrdersdetail> selectOrderByMore(Long advOrdersId) {
        return advOrdersdetailMapper.selectOrderByMore(advOrdersId);
    }


    /**
     * 内容订单明细
     * @param advOrdersId
     * @return
     */
    @Override
    public List<AdvOrdersdetail> selectOrderByMoreTwo(Long advOrdersId) {
        return advOrdersdetailMapper.selectOrderByMoreTwo(advOrdersId);
    }
    @Override
    public List<AdvOrdersdetail> queryOrderByMoreThree(Long advOrdersId) {
        AdvOrders advOrders = advOrdersMapper.selectAdvOrdersByAdvOrdersId(advOrdersId);
        AdvOrders orders = advOrdersMapper.selectByRefOrdersno(advOrders.getOrdersno());
        if(orders != null) {
            return advOrdersdetailMapper.selectOrderByMoreThree(orders.getAdvOrdersId());
        } else {
            return null;
        }
    }

    @Override
    public List<AdvOrdersdetail> selectAdvOrdersdetailListApp(Long ordersId) {
        List<AdvOrdersdetail> advOrdersdetails = advOrdersdetailMapper.selectAdvOrdersdetailListApp(ordersId, null);
        for (AdvOrdersdetail advOrdersdetail : advOrdersdetails) {
            System.out.println("我的订单数据---->"+advOrdersdetail);
        }
        return advOrdersdetails;
    }

    @Override
    public List<AdvOrdersdetail> findBuy(Long advMembersId) {
        return advOrdersdetailMapper.findBuy(advMembersId);
    }

    @Override
    @Transactional
    public int syncProduct(String advMembersId, Long[] advProductIds) {
        System.out.println("advmembersid=" + advMembersId);
        System.out.println("advProductIds=" + advProductIds);
        // 首先要移出所有的上传的设备
        advOrdersdetailMapper.removeSyncProduct(advMembersId);
        // 然后添加设备
        int i = advOrdersdetailMapper.syncProduct(advMembersId, advProductIds);
        return i;
    }

    @Override
    public List<AdvOrdersdetail> queryProductList(AdvOrdersdetail advOrdersdetail) {

        return advOrdersdetailMapper.queryProductList(advOrdersdetail);
    }
}
